#include <stdio.h>
#include <string.h>

typedef struct {
	int count;
	int score;
	char name[13];
} team;

int main() {
	team arr[10] = {{0, 0, "name"}};
	team tmp ;
	int brr[10][10] = {0};
	int n = 0;
	scanf("%d", &n);
	getchar();
	int i = 0;
	int j = 0 ;
	for (i = 0; i < n; i++) {
		scanf("%s", arr[i].name);
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf(" %d", &brr[i][j]);
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (brr[i][j] == 5) {
				arr[i].count++;
				arr[i].score += 2;
			} else if (brr[i][j] == -5) {
				arr[i].score++;
			} else if (brr[i][j] == 4) {
				arr[i].count++;
				arr[i].score += 3;
			} else if (brr[i][j] == 3) {
				arr[i].count++;
				arr[i].score += 3;
			}
		}
	}
	for (i = 0; i < n - 1; i++) {
		int flag = 0;
		for (j = 0; j < n - i - 1; j++) {
			if (arr[j].count < arr[j + 1].count || arr[j].count == arr[j + 1].count && arr[j].score < arr[j + 1].score
			        || arr[j].count == arr[j + 1].count && arr[j].score == arr[j + 1].score && strcmp(arr[j].name, arr[j + 1].name) > 0) {
				tmp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = tmp;
				flag = 1;
			}
		}
		if (flag == 0)
			break;


	}


	for (i = 0; i < n; i++) {
		printf("%s %d %d\n", arr[i].name, arr[i].count, arr[i].score);
	}

	return 0;
}